<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%
  content_for :page_title, join_title(t(:page_title, "Course Details"), @context.name)
  css_bundle :course_settings
  js_bundle :course_settings
  @active_tab = "settings"

  can_manage = can_do(@context, @current_user, :manage)

  can_manage_courses = can_do(@context.account, @current_user, :manage_courses)
  can_rename_course = can_manage_courses || (can_manage && !@context.root_account.settings[:prevent_course_renaming_by_teachers])
  can_manage_master_courses = can_manage_courses && can_do(@context.account, @current_user, :manage_master_courses)
  has_multiple_sections = @context.course_sections.active.count > 1

  can_see_users = can_do(@context, @current_user, :read_roster, :manage_students, :manage_admin_users)

  is_master_course = MasterCourses::MasterTemplate.is_master_course?(@context)
%>

<% content_for :right_side do %>
  {{> views/settings_sidebar}}
<% end %>

<h1 class="screenreader-only"><%= t 'course_settings_title', "Course Settings" %></h1>
<div id="course_details_tabs" style="display:none;" class="ui-tabs-minimal">
  <ul>
    <li id="course_details_tab"><a href="#tab-details">{{#t}}Course Details{{/t}}</a></li>
    <li id="sections_tab"><a href="#tab-sections">{{#t}}Sections{{/t}}</a></li>
    <% if can_do @context, @current_user, :update %>
      <li id="navigation_tab"><a href="#tab-navigation">{{#t}}Navigation{{/t}}</a></li>
    <% end %>
    <% if can_do @context, @current_user, :read_as_admin %>
      <li id="external_tools_tab"><a href="#tab-tools" id="tab-tools-link">{{#t}}Apps{{/t}}</a></li>
    <% end %>
    <% if @publishing_enabled %>
      <li id="grade_publishing_tab"><a href="#tab-grade-publishing" id="tab-grade-publishing-link">{{#t}}Grade Syncing{{/t}}</a></li>
    <% end %>
    <% if @context.root_account.settings[:enable_alerts] && can_do(@context, @current_user, :manage_interaction_alerts) %>
      <li id="alerts_tab"><a href="#tab-alerts" id="tab-alerts-link">{{#t}}Alerts{{/t}}</a></li>
    <% end %>
    <% if can_do @context, @current_user, :manage_feature_flags %>
      <li id="feature_flags_tab"><a href="#tab-features" id="tab-features-link">{{#t}}Feature Options{{/t}}</a></li>
    <% end %>
  </ul>
  <div id="tab-details">
    <h2>
      {{#t}}Course Details{{/t}}
      <% if @context.created? || @context.claimed? %>
        <span id='course-status' class='published-status unpublished pull-right'>
          {{#t}}Course is Unpublished{{/t}}
          {{> icons/unpublished}}
        </span>
      <% else %>
        <% if @context.unpublishable? %>
          <span data-tooltip title="" id='course-status' class='published-status published pull-right'>
            {{#t}}Course is Published{{/t}}
            {{> icons/publish}}
          </span>
        <% else %>
          <% unpublish_tooltip = t('tooltips.cannot_unpublish_course', %{You cannot unpublish this course if there are graded student submissions}) %>
          <span data-tooltip title="<%= unpublish_tooltip %>" id='course-status' class='published-status published pull-right'>
            {{#t}}Course is Published{{/t}}
            {{> icons/publish}}
          </span>
        <% end %>
      <% end %>
    </h2>
    <%= form_tag course_path(@context), :id => "course_reload_form", :method => :put do %>
      <%= hidden_field_tag :for_reload, true %>
      <%= hidden_field_tag :continue_to, course_settings_url(@context) %>
    <% end %>
    <% opts = {:id => "course_form", :class => "formtable"} %>
    <% opts[:disabled] = 'disabled' unless can_manage %>
    <%= form_for @context, :html => opts do |f| %>
    <table class="coursesettings">
      <% if @context.feature_enabled?(:course_card_images) %>
      <tr>
        <td class="form-label"><%= f.blabel :image, :en => "Image" %></td>
        <td>
          <div class="CourseImageSelector__Container"></div>
        </td>
      </tr>
      <% end %>
      <tr>
        <td class="form-label"><%= f.blabel :name, :course_name, :en => "Name" %></td>
        <td class="nobr">
          <% if can_rename_course %>
            <%= f.text_field :name, :class => "course_form", :maxlength => '255', :style => "width: 150px;" %>
          <% else %>
            <span id="course_name"><%= @context.name %></span>
          <% end %>
        </td>
      </tr>
      <tr>
        <td class="form-label nobr"><%= f.blabel :course_code, :en => "Course Code" %></td>
        <td class="nobr">
          <% if can_rename_course %>
            <%= f.text_field :course_code, :maxlength => '255', :style => "width: 100px;" %>
          <% else %>
            <span id="course_course_code"><%= @context.course_code %></span>
          <% end %>
        </td>
      </tr>
      <% if @context.root_account.feature_enabled?(:master_courses) %>
      <tr>
        <td class="form-label nobr"><%= f.blabel :blueprint_course, :en => "Blueprint Course" %></td>
        <td class="nobr">
          <% if can_manage_master_courses %>
            <div id="blueprint_menu"></div>
          <% else %>
            <span id="course_blueprint"><%= is_master_course ? t("Yes") : t("No") %></span>
          <% end %>
        </td>
      </tr>
      <% end %>
      <tr>
        <td><%= f.blabel :time_zone, :en => "Time Zone" %></td>
        <td>
          <% if can_manage %>
            <%= f.time_zone_select :time_zone, I18nTimeZone.us_zones, :model => I18nTimeZone %>
          <% else %>
            <% if name = @context.time_zone.try(:name) %>
              <%= I18n.send(:translate, I18nTimeZone[name].keyify, name.dup) %>
            <% else %>
              {{#t}}None{{/t}}
            <% end %>
          <% end %>
        </td>
      <% if @context.sis_source_id && can_do(@context, @current_user, :read_sis) || can_do(@context, @current_user, :manage_sis) %>
        </tr><tr>
          <td class="form-label"><%= f.blabel :sis_source_id, :en => "SIS ID" %></td>
          <td>
            <% if can_manage && can_do(@context, @current_user, :manage_sis) %>
              <%= f.text_field :sis_source_id, :style => "width: 202px;", :title => t('sis_source_id', "SIS ID"), :value => @context.sis_source_id %>
            <% else %>
              <span id="course_sis_source_id">
                <%= @context.sis_source_id %>
              </span>
            <% end %>
          </td>
      <% end %>
      <% if @current_user && Account.site_admin.account_users_for(@current_user).present? %>
        </tr><tr>
          <td class="form-label"><%= f.blabel :root_account, :en => "Root Account" %></td>
          <td><%= link_to @context.root_account.name, account_url(@context.root_account.id), :id => "course_root_account" %></td>
      <% end %>
      </tr><tr>
        <td class="form-label"><%= f.blabel :account_id, :en => "Subaccount" %></td>
        <td>
          <% can_edit_account = false %>
          <% if can_manage %>
            <% account_chain = @context.account.account_chain.reverse %>
            <% account_chain.each do |account| %>
              <% if can_do(account, @current_user, :manage_courses) %>
                <% if account.root_account? && account.all_accounts.count > Setting.get('course_settings_sub_account_dropdown_limit', '500').to_i %>
                  <a href="<%= context_url(account, :context_sub_accounts_url, :format => :json, :include_self => "1") %>" id="course_account_id_url" style="display: none;">&nbsp;</a>
                  <input type="hidden" name="course[account_id]" id="course_account_id" value="<%= @context.account_id %>"/>
                  <input type="text" name="account[name]" id="course_account_id_lookup" value="<%= @context.account.name %>" style="width: 150px;"/>
                <% else %>
                  <select name="course[account_id]" id="course_account_id">
                    {{> views/shared/account_options}}
                  </select>
                <% end %>
                <% can_edit_account = true %>
                <% break %>
              <% end %>
            <% end %>
          <% end %>

          <% unless can_edit_account %>
            <span id="course_account_id">
              <% if can_do(@context.account, @current_user, :read) %>
                <%= link_to @context.account.name, account_url(@context.account.id) %>
              <% else %>
                <%= @context.account.name %>
              <% end %>
            </span>
          <% end %>
        </td>
      </tr><tr>
        <td class="form-label"><%= f.blabel :enrollment_term_id, :en => "Term" %></td>
        <td>
          <% if can_manage && can_do(@context.account, @current_user, :manage_courses) %>
            <select name="course[enrollment_term_id]" id="course_enrollment_term_id">
              <% @context.root_account.enrollment_terms.active.sort_by{|t| t.start_at || CanvasSort::First}.each do |term| %>
                <option value="<%= term.id %>" <%= 'selected' if term.id == @context.enrollment_term_id %>><%= term.name %></option>
              <% end %>
            </select>
          <% else %>
            <span id="course_enrollment_term_id">
              <%= @context.enrollment_term.name %>
            </span>
          <% end %>
        </td>
      </tr><tr>
        <td class="form-label"><%= f.blabel :start_at, :en => "Starts" %></td>
        <td class="nobr">
          <% if can_manage %>
            <%= f.text_field :start_at, :class => "date_entry", :value => datetime_string(@context.start_at, :verbose) %>
          <% else %>
            <%= datetime_string(@context.start_at, :verbose) %>
          <% end %>
        </td>
      </tr><tr>
        <td class="form-label"><%= f.blabel :conclude_at, :en => "Ends" %></td>
        <td class="nobr tall-row">
          <% if can_manage %>
          <div>
            <%= f.text_field :conclude_at, :class => "date_entry", :value => datetime_string(@context.conclude_at, :verbose) %>
            <i id="course_conclude_at_warning" style="<%= hidden %>" class="date-warning icon-warning" data-tooltip='{"tooltipClass":"popover", "position":"right"}'
               data-html-tooltip-title="<div class='popover-title'>{{#t}}Course Ending at Midnight{{/t}}</div><div class='popover-content'><p>
              <%= t(:course_conclude_at_warning_message, "The course is currently set to end at midnight,
                meaning that the previous day will be the last day this course is active.") %></p></div>">
            </i>

            <%= f.check_box :restrict_enrollments_to_course_dates %>
            <%= f.label :restrict_enrollments_to_course_dates, :en => "Users can only participate in the course between these dates" %>
          </div>

          <div class="aside palign">
            {{#t}}This will override any term availability settings.{{/t}}
          </div>
          <% else %>
            <%= datetime_string(@context.conclude_at, :verbose) %>
          <% end %>
        </td>
      <% unless can_manage %>
        </tr><tr>
        <td class="form-label"></td>
        <td class="nobr">
          <%= f.check_box :restrict_enrollments_to_course_dates, :disabled => true %>
          <%= f.label :restrict_enrollments_to_course_dates, :en => "Users can only participate in the course between these dates" %>
        </td>
      <% end %>
      <% if available_locales.size > 1 %>
      </tr><tr>
        <td class="form-label"><%= f.blabel :locale, :language, :en => "Language" %></td>
        <td class="tall-row">
          <% no_language = t(:no_language_preference, "Not set (user-configurable, defaults to %{language})", :language => available_locales[infer_locale(:context => @context.account)]) %>
          <% if can_manage %>
            <div>
              <%= f.select :locale,
                           [[no_language, nil]] + available_locales.invert.sort_by { |desc, _| Canvas::ICU.collation_key(desc) },
                           {:selected => @context.locale}, {:class => 'locale'} %>
              {{> views/shared/locale_warning}}
              <p> <%= mt :transifex_message, <<-TEXT, :transifex_url => "https://www.transifex.com/instructure/canvas-crowdsource/"
  Join the [Canvas Translation Community](%{transifex_url})
  TEXT
              %>
              </p>
            </div>
            <div class="aside palign">
              {{#t}}This will override any user/system language preferences. This is only recommended for foreign language courses{{/t}}
            </div>
          <% else %>
            <%= @context.locale ? available_locales[@context.locale] : no_language %>
          <% end %>
        </td>
      <% end %>
      </tr><tr>
        <td class="form-label"><%= f.blabel :storage_quota_mb, :storage_quota, :en => "File Storage" %></td>
        <td>
          <% if can_manage && can_do(@context.account, @current_user, :manage_storage_quotas) %>
            <%= f.text_field :storage_quota_mb, :style => "width: 50px;", :title => t('megabytes', "megabytes"), :value => @context.storage_quota_mb %>
          <% else %>
            <%= @context.storage_quota_mb %>
          <% end %>
          {{#t}}megabytes{{/t}}
        </td>
      <% if @context.turnitin_enabled? %>
      </tr><tr>
        <td class="form-label"><%= f.blabel :turnitin_comments, :en => "Turnitin Comments" %></td>
        <td class="nobr">
          <span class="aside">{{#t}}these comments will be shown to students when submitting a Turnitin-enabled assignment{{/t}}</span>
          <br/>
          <%= f.text_area :turnitin_comments, :style => "width: 90%; height: 50px;", :disabled => !can_manage %>
        </td>
      <% end %>
      </tr>
      <tr>
        <td class="form-label">
          <label for="course_grading_scheme"><%= before_label('grading_scheme', %{Grading Scheme}) %></label>
        </td>
        <td id="course_grading_scheme">
          <%= f.check_box :grading_standard_enabled, :class => "grading_standard_checkbox", :disabled => !can_manage %>
          <%= f.label :grading_standard_enabled, :en => "Enable course grading scheme" %>
          <div class="grading_standard_link" style="margin-left: 20px;">
            <a href="#" class="edit_letter_grades_link"><%= @context.grading_standard_enabled? ? t('view_grading_scheme', "view grading scheme") : t('set_grading_scheme', "set grading scheme") %></a>
          </div>
        </td>
      </tr>
      <tr>
        <td class="form-label"><%= f.label :license, :en => "License" %></td>
        <td colspan="3">
          <% if can_manage %>
            <% cc, non_cc = Course.licenses.map { |id, attrs| [attrs[:readable_license].call, id]}.partition{|n, id| id.start_with?('cc')} %>
            <select name="course[license]" id="course_license">
              <%= options_for_select(non_cc, @context.license) %>
              <%= grouped_options_for_select([[t("Creative Commons Licenses"), cc]], @context.license) %>
            </select>
            <%= license_help_link %>
          <% else %>
            <%= @context.readable_license %>
          <% end %>
        </td>
      </tr><tr>
        <td class="form-label"><label for="course_visibility"><%= before_label('course_visibility', %{Visibility}) %></label></td>
        <td colspan="3" id="course_visibility">
          <% if can_manage %>
            <span>
              <%= f.select :course_visibility, @context.course_visibility_options.map{ |id, attrs| [attrs[:setting], id] }, {},  {"aria-label" => t("Course Visibility Options")} %>
              <%= visibility_help_link %>
            </span>
            <div class="panel-border">
              <%= f.check_box :custom_course_visibility %>
              <%= f.label :custom_course_visibility, :en => "Customize" %>
              <% @context.customize_course_visibility_list.map do |setting, options| %>
                <div id="customize_course_visibility">
                  <%= f.label :syllabus_visibility_option, options[:setting] %>
                  <%= f.select :syllabus_visibility_option, @context.course_visibility_options.map{ |id, attrs| [attrs[:setting], "#{id}"] }, {}, {:id => options[:setting], "aria-label" => t("Syllabus Visibility Options")} %>
                </div>
              <% end %>
            </div>
          <% end %>
          <br/>
          <div class="public_options">
            <%= f.check_box :indexed, :disabled => !can_manage %>
            <%= f.label :indexed, :en => "Include this course in the public course index" %>
          </div>
          <br/>
          <div>
            <%= f.check_box :restrict_student_past_view, :disabled => !can_manage || @context.account.restrict_student_past_view[:locked] %>
            <%= f.label :restrict_student_past_view, :en => "Restrict students from viewing course after end date" %>
          </div>
          <div>
            <%= f.check_box :restrict_student_future_view, :disabled => !can_manage || @context.account.restrict_student_future_view[:locked] %>
            <%= f.label :restrict_student_future_view, :en => "Restrict students from viewing course before start date" %>
          </div>
        </td>
      </tr><tr>
        <td class="form-label"><label for="course_course_format"><%= before_label('course_format', %{Format}) %></label></td>
        <% format_options = [[t('#course.course_format.not_set', 'Not Set'), ''],
          [t('#course.course_format.on_campus', "On-Campus"), "on_campus"],
          [t('#course.course_format.online', "Online"), "online"],
          [t('#course.course_format.blended', "Blended"), "blended"]] %>
        <td>
          <% if can_manage %>
            <%= f.select :course_format, format_options %>
          <% else %>
            <%= (format_options.detect{|text, key| key == @context.course_format} || format_options.first).first %>
          <% end %>
        </td>
      </tr>
      <% if @context.feature_enabled?(:epub_export) && !@context.account.enable_offline_web_export? %>
        <tr>
          <td class="form-label"><label for="course_epub_export"><%= before_label('course_epub_export', %{Epub Export}) %></label></td>
          <td colspan="3" id="epub_export">
            <div>
              <%= f.check_box :organize_epub_by_content_type, :disabled => !can_manage %>
              <%= f.label :organize_epub_by_content_type, t("Organize epub by content type (default is by module).") %>
            </div>
          </td>
        </tr>
      <% end %>
      <% if @context.account.enable_offline_web_export? %>
        <tr>
          <td class="form-label"><label for="course_offline_export"><%= before_label('course_offline_export', %{Offline Course}) %></label></td>
          <td colspan="3" id="offline_web_export">
            <div>
              <%= f.check_box :enable_offline_web_export, :disabled => !can_manage %>
              <%= f.label :enable_offline_web_export, t("Allow course content to be downloaded and viewed offline") %>
            </div>
          </td>
        </tr>
      <% end %>
      <tr>
        <td class="form-label"><label for="course_public_description"><%= before_label('course_description', %{Description}) %></label></td>
        <td colspan="3">
          <%= f.text_area :public_description, :style => "height: 100px;", :disabled => !can_manage %>
        </td>
      </tr><tr>
        <td></td>
        <td colspan="3">
          <span class="self_enrollment_message" style="<%= hidden unless @context.self_enrollment_enabled? %>">
            <% if @context.root_account.self_registration? %>
              <%= t 'course_open_enrollment', <<-TEXT, :url => enroll_url(@context.self_enrollment_code || '{{ self_enrollment_code }}'), :url2 => register_url, :code => @context.self_enrollment_code || '{{ self_enrollment_code }}', :wrapper => '<b>\1</b>'
                    This course has enabled open enrollment. Students can
                    self-enroll in the course once you share with them this URL:
                    *%{url}*. Alternatively, they can sign up at *%{url2}* and
                    use the following join code: *%{code}*
                  TEXT
              %>
            <% else %>
              <%= t 'course_open_enrollment_without_code', <<-TEXT, :url => enroll_url(@context.self_enrollment_code || '{{ self_enrollment_code }}'), :wrapper => '<b>\1</b>'
                    This course has enabled open enrollment. Students can
                    self-enroll in the course once you share with them this URL:
                    *%{url}*
                  TEXT
              %>
            <% end %>
          </span>
          <a href="#" role="button" class="course_form course_form_more_options_link" style="padding-left: 20px;">{{#t}}more options{{/t}}</a>
          <div class="course_form_more_options" style="display: none; padding-left: 20px;">
            <% if @context.self_enrollment_allowed? %>
              <%= f.check_box :self_enrollment, :class => 'self_enrollment_checkbox', :disabled => !can_manage %>
              <label for="course_self_enrollment">
                <% if @context.root_account.self_registration? %>
                  <%= t :self_enrollment, "Let students self-enroll by sharing with them a secret URL or code" %>
                <% else %>
                  <%= t :self_enrollment_without_code, "Let students self-enroll by sharing with them a secret URL" %>
                <% end %>
              </label><br/>
              <div class="open_enrollment_holder" style="display: none;">
              <%= f.check_box :open_enrollment, :disabled => !can_manage %>
              <%= f.label :open_enrollment, :en => "Add a \"Join this Course\" link to the course home page" %><br/>
              </div>
            <% end %>
            <%= f.check_box :show_announcements_on_home_page, :disabled => !can_manage %>
            <%= f.label :show_announcements_on_home_page, :en => "Show recent announcements on Course home page" %><br/>
            <%= f.select :home_page_announcement_limit, options_for_select(1..15, @context.home_page_announcement_limit || 3), {}, {:disabled => !can_manage || !@context.show_announcements_on_home_page?, :style => 'width: 75px'} %>
            <%= f.label :home_page_announcement_limit, :en => 'Number of announcements shown on the homepage' %><br/>
            <%= f.check_box :allow_student_forum_attachments, :disabled => !can_manage %>
            <%= f.label :allow_student_forum_attachments, :en => "Let students attach files to discussions" %><br/>
            <%= f.check_box :allow_student_discussion_topics, :disabled => !can_manage %>
            <%= f.label :allow_student_discussion_topics, :en => "Let students create discussion topics" %><br/>
            <%= f.check_box :allow_student_discussion_editing, :disabled => !can_manage %>
            <%= f.label :allow_student_discussion_editing, :en => "Let students edit or delete their own discussion posts" %><br/>
            <%= f.check_box :allow_student_organized_groups, :disabled => !can_manage %>
            <%= f.label :allow_student_organized_groups, :en => "Let students organize their own groups" %><br/>
            <%= f.check_box :hide_final_grades, :disabled => !can_manage %>
            <%= f.label :hide_final_grades, :en => "Hide totals in student grades summary" %><br/>
            <%= f.check_box :hide_distribution_graphs, :disabled => !can_manage %>
            <%= f.label :hide_distribution_graphs, :en => "Hide grade distribution graphs from students" %><br/>
            <%= f.check_box :lock_all_announcements, :disabled => !can_manage || @context.account.lock_all_announcements[:locked] %>
            <%= f.label :lock_all_announcements, :en => 'Disable comments on announcements' %><br />
            <%= f.select :default_wiki_editing_roles, [
              [t('#course.wiki_permissions.only_teachers', "Only Teachers"), "teachers"],
              [t('#course.wiki_permissions.teachers_students', "Teacher and Students"), "teachers,students"],
              [t('#course.wiki_permissions.all', "Anyone"), "teachers,students,public"]], {}, :disabled => !can_manage %>
            <label for="course_default_wiki_editing_roles">
              <%= t(%{can create, rename, and edit course pages by default}) %>
            </label><br/>
            <div class="changed_default_wiki_editing_roles" style="display: none; padding-left: 20px; font-size: 0.8em;">
              <input type="checkbox" name="update_default_pages" id="update_default_pages"/>
              <label for="update_default_pages"><%= t 'wiki_editing_roles_change_existing', %{Change pages currently editable by "%{current_setting}" to "%{new_setting}".}, :current_setting => content_tag('span', @context.readable_default_wiki_editing_roles), :new_setting => content_tag('span', nbsp, :class => 'default_wiki_editing_roles_change') %></label>
            </div>
          </div>
        </td>
      </tr>
      <% if can_manage %>
        <tr>
          <td colspan="4">
            <% if Setting.get('cross_root_account_course_moves', 'false') == 'true' && Account.site_admin.grants_right?(@current_user, :manage_courses) && Account.root_accounts.length > 1 %>
              <a href="#" class="move_course_link btn">{{> icons/arrow-right}} {{#t}}Move To Another Account{{/t}}</a>
            <% end %>
            <span class="course_form">
              <div class="form-actions">
                <button type="submit" class="btn btn-primary">{{#t}}Update Course Details{{/t}}</button>
              </div>
            </span>
          </td>
        </tr>
      <% end %>
    </table>
    <% end %>
  </div>
  <div id="tab-sections">
    <h2 style="margin-top: 10px;">{{#t}}Course Sections{{/t}}</h2>
    <ul id="sections">
      <% @context.course_sections.active.order(CourseSection.best_unicode_collation_key('name')).each do |section| %>
        <li class="section">
          <% if can_do section, @current_user, :read %>
            <a href="<%= context_url(@context, :context_section_url, section) %>" class="name">
              <%= section.display_name %>
            </a>
          <% else %>
            <span class="name">
              <%= section.display_name %>
            </span>
          <% end %>
          <span class="users_count">
            (
              <%= t 'enrollment_count', 'User', :count => section.enrollments.not_fake.where.not(:workflow_state => "rejected").count %><% if section && section.sis_source_id %>,
                <%= t 'section_sis_id', 'SIS ID: %{section_sis}', :section_sis => section.sis_source_id %>
              <% end %>
            )
          </span>
          <span class="section_links">
            <% if can_do(section, @current_user, :update) && !section.defined_by_sis? %>
              <a class="Button Button--icon-action edit_section_link"
                role="button"
                title="{{#t}}Edit Section{{/t}}"
                href="<%= context_url(@context, :context_section_url, section) %>">
                {{> icons/edit}}
                <span class="screenreader-only"><%= t('Edit Section "%{name}"', :name => section.name) %></span>
              </a>
            <% end %>
            <% if can_do(section, @current_user, :delete) %>
              <% if section.deletable? %>
                <a class="Button Button--icon-action delete_section_link"
                  role="button"
                  title="{{#t}}Delete Section{{/t}}"
                  href="<%= context_url(@context, :context_section_url, section) %>">
                  {{> icons/end}}
                  <span class="screenreader-only">
                    <%= t('Delete Section "%{name}"', :name => section.name) %>
                  </span>
                </a>
              <% else %>
                <a class="Button Button--icon-action cant_delete_section_link"
                  role="button"
                  href="#"
                  title="{{#t}}You can't delete sections that have users enrolled{{/t}}">
                  {{> icons/end}}
                  <span class="screenreader-only"><%= t('Delete Section "%{name}"', :name => section.name) %></span>
                </a>
              <% end %>
            <% end %>
          </span>
          <div class="clear"></div>
        </li>
      <% end %>
      <li class="section_blank" style="display: none;">
        <a href="<%= context_url(@context, :context_section_url, "{{ id }}") %>" class="name"></a>
        <span class="section_links">
          <a class="Button Button--icon-action no-hover edit_section_link"
            role="button"
            href="<%= context_url(@context, :context_section_url, "{{ id }}") %>"
            title="{{#t}}Edit Section{{/t}}">
              {{> icons/edit}}
              <span class="screenreader-only">
                <%= t('Edit Section "%{name}"', :name => "%%name%%") %>
              </span>
          </a>
          <a class="Button Button--icon-action delete_section_link"
            role="button"
            href="<%= context_url(@context, :context_section_url, "{{ id }}") %>"
            title="{{#t}}Delete Section{{/t}}"
            class="no-hover">
              {{> icons/end}}
              <span class="screenreader-only"><%= t('Delete Section "%{name}"', :name => "%%name%%") %></span>
          </a>
        </span>
        <div class="clear"></div>
      </li>
      <% if can_do(@context.course_sections.temp_record, @current_user, :create) %>
        <li>
          <%= form_for :course_section, :url => context_url(@context, :context_sections_url), :html => {:id => "add_section_form", :class => "form-inline", :style => "margin-top: 20px;"} do |f| %>
            <h3><%= f.blabel :name, :course_section_name, :en => "Add a New Section" %></h3>
            <%= f.text_field :name %>
            <button class="btn btn-primary" type="submit" title="{{#t}}Add Section') %>" aria-label="{{#t}}Section{{/t}}</button>
          <% end %>
        </li>
      <% end %>
    </ul>
    <%= form_for :course_section, :url => "", :html => {:id => "edit_section_form", :method => :put, :style => "display: none;"} do |f| %>
      <%= f.text_field :name, :id => "course_section_name_edit", :'aria-label' => t('buttons.edit_section_name', "Edit section name") %>
    <% end %>
  </div>
  <% if can_do @context, @current_user, :update %>

  <div id="tab-navigation">
    <h2 class="screenreader-only">{{#t}}Course Navigation{{/t}}</h2>
    <div class="screenreader-only drag_and_drop_warning" tabindex="0">
      <%= t('nav_items_keyboard_drag_and_drop',
      'Warning: For improved accessibility in reordering Course Navigation elements, please use the Move To Dialog option found in the menu.') %>
    </div>

    <% keyboard_navigation([
         {:key => t('keycodes.next_navigation_link', 'Up'), :description => t('keycode_descriptions.next_navigation_link', 'Select next navigation link')},
         {:key => t('keycodes.previous_navigation_link', 'Down'), :description => t('keycode_descriptions.previous_navigation_link', 'Select previous navigation link')},
         {:key => t('keycodes.toggle_navigation_dragging', 'Space'), :description => t('keycode_descriptions.toggle_navigation_dragging', 'Select link to begin dragging, or drop previously selected link')}
     ]) %>

    <%= form_tag context_url(@context, :context_update_nav_url), {:id => "nav_form", :title => t('titles.edit_navigation', "Edit Course Navigation") } do %>
      <input type="hidden" name="tabs_json" id="tabs_json" value="[]" />
      <% tabs = sortable_tabs %>
      <p style="margin-bottom: 4px; padding-top: 10px">
        {{#t}}Drag and drop items to reorder them in the course navigation.{{/t}}
      </p>
      <% tabs.each do |tab|
        tab[:disabled_message] = [Course::TAB_GRADES, Course::TAB_PEOPLE, Course::TAB_DISCUSSIONS].include?(tab[:id]) ? t('tab_cant_disable', "This page can't be disabled, only hidden") : t('tab_disabled', "Page disabled, will redirect to course home page")
        tab[:disabled_message] = t("tab_hidden_if_disabled", "Page disabled, won't appear in navigation") if tab[:external]
      end %>
      <h3 class="screenreader-only">{{#t}}Enabled Links{{/t}}</h3>
      <ul id="nav_enabled_list" class="nav_list connectedSortable">
        <% tabs.select {|t| !t[:hidden] }.each do |tab|  %>
          <li aria-label="<%= tab[:label] %>" class="navitem <%= 'enabled' if tab[:id] != Course::TAB_HOME %> <%= tab[:label].downcase %>"
              id="nav_edit_tab_id_<%= tab[:id] %>"
              tabindex="0"
          >
            <%= tab[:label] %>
            <div class="admin-links">
              <a class="al-trigger al-trigger-gray" role="button" href="#">
                {{> icons/settings}}
                {{> icons/mini-arrow-down}}
                <span class="screenreader-only">
                  <span class="screenreader-only">
                    <%= t('Settings for %{tab_label}', { tab_label: tab[:label]}) %>
                  </span>
                </span>
              </a>

              <ul class="al-options" role="menu" tabindex="0" aria-hidden="true" aria-expanded="false" aria-activedescendant="content-2">
                <li role="presentation">
                  <a href="#" class="icon-x disable_nav_item_link" id="disable_nav_item_link_<%= tab[:id] %>" role="menuitem" title="Disable this item">{{#t}}Disable{{/t}}</a>
                </li>
                <li role="presentation">
                  <a href="#" class="icon-updown move_nav_item_link" id="move_nav_item_link_<%= tab[:id] %>" role="menuitem" title="Move this item">{{#t}}Move{{/t}}</a>
                </li>
              </ul>
            </div>
            <span class="disabled_message"><%= tab[:disabled_message] %></span>
          </li>

        <% end %>
      </ul>

      <h3 class="screenreader-only">{{#t}}Disabled Links{{/t}}</h3>
      <ul id="nav_disabled_list" class="nav_list connectedSortable">
        <li class="disabled">
          {{#t}}Drag items here to hide them from students.{{/t}}
          <div style="font-size: 0.8em;">
            {{#t}}Disabling most pages will cause students who visit those pages to be redirected to the course home page.{{/t}}
          </div>
        </li>
        <% tabs.select {|t| t[:hidden] }.each do |tab|  %>
          <li aria-label="<%= tab[:label] %>"
              class="navitem enabled"
              id="nav_edit_tab_id_<%= tab[:id] %>"
              tabindex="0"
          >
            <%= tab[:label] %>
            <div class="admin-links">
                <a class="al-trigger al-trigger-gray" role="button" href="#">
                  {{> icons/settings}}
                  {{> icons/mini-arrow-down}}
                  <span class="screenreader-only"><%= t('Settings for %{tab_label}', { tab_label: tab[:label]}) %></span>
                </a>

                <ul id="content-2" class="al-options" role="menu" tabindex="0" aria-hidden="true" aria-expanded="false" aria-activedescendant="content-3">
                  <li role="presentation">
                    <a href="#" class="icon-plus enable_nav_item_link" id="enable_nav_item_link_<%= tab[:id] %>" role="menuitem" title="Enable this item">{{#t}}Enable{{/t}}</a>
                  </li>
                  <li role="presentation">
                    <a href="#" class="icon-updown move_nav_item_link" id="move_nav_item_link_<%= tab[:id] %>" role="menuitem" title="Move this item">{{#t}}Move{{/t}}</a>
                  </li>
                </ul>
              </div>
              <span class="disabled_message"><%= tab[:disabled_message] %></span>

          </li>
        <% end %>
      </ul>

      <p>
        <button type="submit" class="btn btn-primary">{{#t}}Save{{/t}}</button>
      </p>
    <% end %>
  </div>

  <% end %>

  <% if can_do @context, @current_user, :read_as_admin %>
    <div id="tab-tools">
      {{> views/external_tools/external_tools}}
    </div>
  <% end %>

  <% if @publishing_enabled %>
    <div id="tab-grade-publishing">
      <h2>{{#t}}Grade Syncing{{/t}}</h2>
      <%= form_tag context_url(@context, :context_publish_to_sis_url), { :id => "publish_to_sis_form", :style => "display: none;" } do %><% end %>
      <a href="#" id="publish_grades_link" class="btn disabled">...</a>
      <ul id="publish_grades_messages"></ul>
    </div>
  <% end %>

  <% if @context.root_account.settings[:enable_alerts] && can_do(@context, @current_user, :manage_interaction_alerts) %>
    <div id="tab-alerts">
      <h2>{{#t}}Alerts{{/t}}</h2>
      {{> views/alerts/alerts}}
    </div>
  <% end %>

  <% if can_do @context, @current_user, :manage_feature_flags %>
    <div id="tab-features"></div>
  <% end %>
</div><!-- end course details tab -->

<% if Account.site_admin.grants_right?(@current_user, :manage_courses) %>
  <div id="move_course_dialog" style="display: none;">
    <h2>{{#t}}Move the course to another root account{{/t}}</h2>
    {{#t}}Select a new root account for this course.  After you move the course you'll want to specify a new department for the course as well.{{/t}}
    <%= form_for :course, :url => course_url(@context), :html => {:method => :put} do |f| %>
      <table class="formtable">
        <tr>
          <td>
            <%= f.blabel :root_account_id, :en => "Root Account" %>
          </td>
          <td>
            <%= f.select :root_account_id, Account.root_accounts.active.order("name DESC").select([:id, :name]).map{|a| [a.name, a.id] }, :selected => @context.root_account_id %>
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <div class="button-container">
              <button type="button" class="btn cancel_button">{{#t}}Cancel{{/t}}</button>
              <button type="submit" class="btn btn-primary">{{#t}}Move Course{{/t}}</button>
            </div>
          </td>
        </tr>
      </table>
    <% end %>
  </div>
<% end %>
<div id="edit_letter_grades_form" style="display: none;" data-context_code="<%= @context.asset_string %>">
  <%= render partial: "shared/grading_standard", object: @context.grading_standard, locals: {read_only: !can_manage} %>
  <a href="<%= context_url(@context, :context_grading_standards_url) %>" style="display: none;" class="create_grading_standard_url">&nbsp;</a>
  <a href="<%= context_url(@context, :context_grading_standard_url, "{{ id }}") %>" style="display: none;" id="update_grading_standard_url">&nbsp;</a>
  <a href="<%= context_url(@context, :context_url) %>" style="display: none;" id="update_course_url">&nbsp;</a>
</div>
